package yao.xiao.liu;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

public class MyView extends View {
	Bitmap bitmap;
	Paint mPaint;
	public MyView(Context context) {
		super(context);
		mPaint=new Paint();
		// TODO Auto-generated constructor stub
	}

	public MyView(Context context, AttributeSet attrs) {
		super(context, attrs);
		Log.d("context", "context-------------->"+context);
		TypedArray typeArray=context.obtainStyledAttributes(attrs,R.styleable.myview);
		int color=typeArray.getColor(R.styleable.myview_textColor,0x00ffff);
		float size=typeArray.getDimension(R.styleable.myview_textSize, 12);
		mPaint=new Paint();
		 mPaint.setColor(color);
		  mPaint.setTextSize(size); 
		  typeArray.recycle();
		
	//init();
	}

	private void init() {
		BitmapDrawable bitmapDrawable=(BitmapDrawable)this.getResources().getDrawable(R.drawable.icon);
		 bitmap=bitmapDrawable.getBitmap();
		
	}

	public MyView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onDraw(Canvas canvas) {
//		Matrix matrix=new Matrix();
//		matrix.postTranslate(10, 10);
//		//matrix.setScale(bitmap.getWidth(), sy);
//		canvas.drawBitmap(bitmap, matrix, null);
		canvas.drawText("你好你好", 0, -100, mPaint);
		canvas.drawRect(new Rect(10,10,100,100), mPaint);
		super.onDraw(canvas);
	}

}
